<?php
   class front_gallery{
    private $template;
    private $util;
    private $db;
    //variable
    private $act;
    private $id;
    private $lang;
    public function __construct(){
        require_once 'code/util.class.php';
        require_once("code/pagination.class.php");      
        $this->util = new util();
        $this->db = new db();
    }
    
    public function autorun(){
        $act =  isset($_GET['act'])?$_GET['act']:'index'; 
        $this->id = isset($_GET['id'])?$_GET['id']:0;  
        $this->lang = isset($_GET['l'])?$_GET['l']:'en';        
        switch($act){
            case 'guestbook':
                $this->guestbook();
                break;
             case 'artist':
                $this->artist();
                break;
            case 'index':
                $this->get_index();
                break;
            case 'contact':
                $this->get_contact_form();
                break;
            case 'docontact':
                $this->do_contact();
                break;
            case 'event':
                $this->get_events();
                break;
            default:
                $this->get_index(); 
                break;   
            
        }
          
    }
    private function artist(){
        $code = isset($_GET['code'])?$_GET['code']:'list';
        
        switch($code){
            case 'detail':
                $this->view_detail();
                break;
            case 'list':
                $this->list_artist();
                break;
            default:
                $this->list_artist();
                break;
        }     
    }
         //Get artist 
    private function list_artist(){ 
        $this->db->openconnection();
        $sql = "SELECT * FROM artist WHERE ishow='1'";     
        $artist = $this->db->run_query($sql);
        $this->db->closeconnection();
 
        $this->db->openconnection();
        $sql = "SELECT * FROM images WHERE site='1' and ishow='1'";     
        $images = $this->db->run_query($sql);
        $this->db->closeconnection();
        
        $pagination = new pagination;
        $artistPages = $pagination->generate($artist,9);
        
        $this->util->send_var('data',$artistPages);
        $this->util->send_var('images',$images);
        $this->util->send_var('module','artist');
        $this->util->send_var('pagination',$pagination->links());  
        return ($this->util->generate_page('../templates/frontend/' . $this->lang . '/gallery/index.tpl')); 
    } 
    private function guestbook(){
        $filter = isset($_GET['filter'])?$_GET['filter']:'top';
        
        switch($filter){
            case '1':
                $this->list_gb_scans();
                break;
            case '2':
                $this->list_gb_posts();
                break;
            case 'top':
                $this->list_guestbook();
                break;
            default:
                $this->list_guestbook();
                break;
        }     
    }
       //Get guestbook 
    private function list_guestbook(){ 
        $this->db->openconnection();
        $sql = "SELECT * FROM guestbook WHERE site='1' and ishow='1' and type='1' ORDER BY createdate";     
        $gbscans = $this->db->run_query($sql);
        $this->db->closeconnection();
     
        $this->db->openconnection();
        $sql = "SELECT * FROM guestbook WHERE site='1' and ishow='1' and type='2' ORDER BY createdate";     
        $gbpost = $this->db->run_query($sql);
        $this->db->closeconnection();
        
        $this->db->openconnection();
        $sql = "SELECT * FROM images WHERE site='1' and ishow='1'";     
        $images = $this->db->run_query($sql);
        $this->db->closeconnection();
        
        $this->util->send_var('gbscans',$gbscans);
        $this->util->send_var('gbpost',$gbpost);
        $this->util->send_var('images',$images);
        $this->util->send_var('module','top_guestbook'); 
        return ($this->util->generate_page('../templates/frontend/' . $this->lang . '/gallery/index.tpl')); 
    } 
         //Get guestbook 
    private function list_gb_scans(){ 
        $this->db->openconnection();
        $sql = "SELECT * FROM guestbook WHERE site='1' and ishow='1' and type='1' ORDER BY createdate";     
        $gbscans = $this->db->run_query($sql);
        $this->db->closeconnection();
 
        $this->db->openconnection();
        $sql = "SELECT * FROM images WHERE site='1' and ishow='1'";     
        $images = $this->db->run_query($sql);
        $this->db->closeconnection();
        
        $pagination = new pagination;
        $scanPages = $pagination->generate($gbscans,3);
        
        $this->util->send_var('data',$scanPages);
        $this->util->send_var('images',$images);
        $this->util->send_var('module','guestbook_scans');
        $this->util->send_var('pagination',$pagination->links());  
        return ($this->util->generate_page('../templates/frontend/' . $this->lang . '/gallery/index.tpl')); 
    } 
             //Get guestbook 
    private function list_gb_posts(){ 
        $this->db->openconnection();
        $sql = "SELECT * FROM guestbook WHERE site='1' and ishow='1' and type='2' ORDER BY createdate";     
        $gbposts = $this->db->run_query($sql);
        $this->db->closeconnection();
 
        $this->db->openconnection();
        $sql = "SELECT * FROM images WHERE site='1' and ishow='1'";     
        $images = $this->db->run_query($sql);
        $this->db->closeconnection();
        
        $pagination = new pagination;
        $postPages = $pagination->generate($gbposts,1);
        
        $this->util->send_var('data',$postPages);
        $this->util->send_var('images',$images);
        $this->util->send_var('module','guestbook_posts'); 
        $this->util->send_var('pagination',$pagination->links()); 
        return ($this->util->generate_page('../templates/frontend/' . $this->lang . '/gallery/index.tpl')); 
    } 
    
     //Get book form
    private function get_events(){ 
        $this->db->openconnection();
        $sql = "SELECT * FROM event WHERE site='1' and ishow='1'";     
        $data = $this->db->run_query($sql);
        $this->db->closeconnection();
 
        $this->db->openconnection();
        $sql = "SELECT * FROM images WHERE site='1' and ishow='1'";     
        $images = $this->db->run_query($sql);
        $this->db->closeconnection();
        
        $pagination = new pagination;
        $postPages = $pagination->generate($data,2);
        
        $this->util->send_var('data',$postPages);
        $this->util->send_var('images',$images);
        $this->util->send_var('module','list_event'); 
        $this->util->send_var('pagination',$pagination->links()); 
        return ($this->util->generate_page('../templates/frontend/' . $this->lang . '/gallery/index.tpl')); 
    } 

     //Get book form
    private function get_contact_form(){ 
        $this->db->openconnection();
        $sql = "SELECT * FROM images WHERE site='1' and ishow='1'";     
        $images = $this->db->run_query($sql);
        $this->db->closeconnection();
     
        $this->util->send_var('images',$images);
        $this->util->send_var('module','contact'); 
        $this->util->generate_page('../templates/frontend/' . $this->lang . '/gallery/index.tpl'); 
    } 
      //Get book form
    private function do_contact(){ 
         //take input
        
 
        return ($this->util->generate_page('../templates/frontend/' . $this->lang . '/gallery/book_result.tpl')); 
    } 
 
    //Get index
    private function get_index(){ 
        $sql = "SELECT * FROM about WHERE site IN ('1','4','5') and ishow='1' ORDER BY site ASC";
        $this->db->openconnection();
        $about = $this->db->run_query($sql);
         
        $sql = "SELECT * FROM images WHERE site='1' and ishow='1'";     
       
        $images = $this->db->run_query($sql);
        
        $this->db->closeconnection();
        $this->util->send_var('module','about'); 
        $this->util->send_var('data',$about); 
        $this->util->send_var('images',$images);
 
        return ($this->util->generate_page('../templates/frontend/' . $this->lang . '/gallery/index.tpl')); 
    } 
} 
?>
